<?php
class FEXCEL {
    var $linha, $separador, $buffer;

    function FEXCEL($separador="\t") {
       $this->separador = $separador;
       $this->linha = '';
       $this->buffer = '';
    }

    function Header() {
 	   //To be implemented in your own inherited class
    }

    function Open () {
       $this->buffer = '';
       $this->Header();
       $this->linha = '';
    }

    function Cell ($conteudo) {
       $this->linha .= ((!empty($this->linha))?$this->separador:'').$conteudo;
    }

    function Ln () {
       $this->buffer .= $this->linha."\r\n";
       $this->linha = '';
    }

    function Close () {
       $this->buffer .= $this->linha."\r\n";
       $this->linha = '';
    }

    function Output ($name='') {
       $this->Close();
       
       if($name=='')
          $name = 'relatorio';
       if(php_sapi_name()!='cli'){
          header('Content-Type: application/vnd.ms-excel');
          if (headers_sent())
             $this->Error('Some data has already been output to browser, can\'t send XLS file');
          header('Content-Length: '.strlen($this->buffer));
          header('Content-disposition: inline; filename="'.$name.'.xls"');
       }
       echo $this->buffer;
    }
}
?>
